package sample;
import controller.MainController;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;


public class MainApplication extends Application {
    public void start(Stage primaryStage) throws Exception{
       try {
           FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
           Parent root =loader.load();
           Button button1 = (Button) root.lookup("#mbutton1");
           Button button2 = (Button) root.lookup("#mbutton2");
           EventHandler<MouseEvent> eventEventHandler1 = new EventHandler<MouseEvent>() {
               @Override
               public void handle(MouseEvent event) {
                   MainController mainController = loader.getController();
                   try {
                       if(mainController.click())primaryStage.close();
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
               }
                   };
           EventHandler<MouseEvent> eventEventHandler2 = new EventHandler<MouseEvent>() {
               @Override
               public void handle(MouseEvent event) {
                   MainController mainController = loader.getController();
                   try {
                       mainController.click2();
                   } catch (Exception e) {
                       e.printStackTrace();
                   }
               }
           };
           button1.addEventHandler(MouseEvent.MOUSE_CLICKED,eventEventHandler1);
           button2.addEventHandler(MouseEvent.MOUSE_CLICKED,eventEventHandler2);
           primaryStage.setTitle("test");
           Scene sc;
           sc = new Scene(root,620,430);
           primaryStage.setScene(sc);
           primaryStage.setResizable(false);
           primaryStage.show();
       }catch (Exception e){
           e.printStackTrace();
       }
    }

    public static void main(String[] args) {
        launch(args);
    }
}




//           //登录

//           //注册
//           EventHandler<MouseEvent> eventHandler =
//                   new EventHandler<MouseEvent>() {
//                       public void handle(javafx.scene.input.MouseEvent e) {
//                           System.out.println("Hello World");
//                           try {
//                               new Register().start(new Stage());
//                           } catch (Exception exception) {
//                               exception.printStackTrace();
//                           }
//                       }
//                   };
//           button1.addEventHandler(MouseEvent.MOUSE_CLICKED,);
//           button2.addEventHandler(MouseEvent.MOUSE_CLICKED,eventHandler);